package org.fei.ClassDiagram.Compiler;


import org.apache.tools.ant.module.api.support.ActionUtils;
import org.fei.ClassDiagram.WindowComponents.Message;
import org.openide.execution.ExecutorTask;
import org.openide.filesystems.FileObject;


/**
 * Trieda obsahuje metodu run, ktora spusta prikaz compile z ant scriptu
 * vstup je subor build-impl.xml (ant script)
 * 
 * @author Tomas
 */
public class AntCompilator {
    
    public static int run(FileObject buildImpl) {

        //AntTargetExecutor.Env env = new AntTargetExecutor.Env();
        //AntTargetExecutor at = AntTargetExecutor.createTargetExecutor(env);
        
        try {
            //DataObject dob = DataObject.find(buildImpl);
            // prikazy pre ant script
            String[] targets = {"clean", "compile"};
            ExecutorTask task = ActionUtils.runTarget(buildImpl, targets, null);

            // supstenie prikazov
            //ExecutorTask task = at.execute(dob.getCookie(AntProjectCookie.class), targets);
            int result = task.result();
            
            //Message.showMessage(String.valueOf(result));
            if (result != 0) {
                return 0;
            }
            return 1;
        } catch (Exception ex) {
            Message.showMessage("AntCompilator.java: " + ex.toString());
            return 0;
        }   
    }
}
